<template>
  <div id="comAlert" v-show="show">
    <div class="alert_inner">
      <p class="alert_title">{{ title }} <i class="el-dialog__close el-icon el-icon-close" @click="alClose"></i></p>
      <p class="alert_info" v-if="info">{{ info }}</p>
      <div class="alert_inbox" v-html="infoHtml" v-if="infoHtml"></div>
      <div class="alert_show" v-if="kai"> <i v-bind:class="[iconTip ? 'icon-xuanzhong' : 'icon-xuanzekuang', 'iconfont']" @click="toggleIco"></i> <span>以后不再提示</span></div>
      <div class="alert_btn">
        <el-button size='small' :type="index==0? 'success': ''"  class="alert_buttons" v-for="(item, index) in button" :key="index" @click="buttonClick(item.callback)" v-if="button.length !== 1">{{ item.text }}</el-button>
        <el-button size='small' type= 'success' class="alert_button" @click="buttonClick(button[0].callback)" v-else>{{ button[0].text }}</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'comAlert',
  data () {
    return {
      show: false,
      title: '',
      info: '',
      infoHtml: '',
      button: [],
      iconTip: false,
      kai: ''
    };
  },
  mounted () {
    this.$bus.$on('comAlert', config => {
      if (!config) return (this.show = false);
      this.show = true;
      this.title = config.title;
      this.info = config.info;
      this.kai = config.kai;
      this.iconTip = config.iconTip;
      this.infoHtml = config.infoHtml;
      this.button = config.button;
    });
  },
  methods: {
    buttonClick (cb) {
      this.$bus.$emit('comAlert', false);
      cb();
    },
    alClose () {
      this.show = false;
    },
    toggleIco () {
      this.iconTip = !this.iconTip;
      // 开机以后是否不再提示
      if (this.kai === 1 && this.iconTip === true) {
        localStorage.setItem('kaiji', '1');
        this.$bus.$emit('dataStatus', {'kaiji': '1'});
      } else if (this.kai === 1 && this.iconTip === false) {
        localStorage.removeItem('kaiji');
        this.$bus.$emit('dataStatus', {'kaiji': '0'});
      }
      // 关机是否以后不再提示
      if (this.kai === 2 && this.iconTip === true) {
        localStorage.setItem('guanji', '1');
        this.$bus.$emit('dataStatus', {'guanji': '1'});
      } else if (this.kai === 2 && this.iconTip === false) {
        localStorage.removeItem('guanji');
        this.$bus.$emit('dataStatus', {'guanji': '0'});
      }
    }
  }
};
</script>

<style lang="scss">
  #comAlert {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.6);
    .icon-xuanzhong {
            color: #f6d68c;
        }
    .alert_inner {
      width: 482px;
      box-sizing: border-box;
      padding: 20px;
      background: #ffffff;
      position: absolute;
      top:40%;
      left: 50%;
      transform: translate(-50%,-50%);
      .alert_title {
        line-height: 24px;
        font-size: 18px;
        color: #303133;
        position: relative;
        i {
          position: absolute;
          right: 0;
          cursor: pointer;
          color: #999999;
        }
      }
      .alert_info {
        margin-top: 30px;
        font-size: 18px;
        color: #999999;
        line-height: 1.5;
      }
      .alert_show {
        margin-top: 20px;
        font-size:14px;
        color:rgba(153,153,153,1);
      }
      .alert_inbox {
        margin-top: 10px;
        color: #999999;
        .el-icon-warning {
          color: #f2bd07;
          margin-right: 8px;
        }
        .eggRule{
          margin-bottom: 30px;
          .num{
            color: #fff;
            background-color: #10a57d;
            display: inline-block;
            width: 25px;
            height: 25px;
            line-height: 25px;
            text-align: center;
            border-radius: 100%;
            vertical-align: top;
          }
          div{
            display: inline-block;
            margin-left: 10px;
            vertical-align: top;
            p {
            margin-top: 5px;
            }
          }
        }
      }
      .alert_btn {
        padding-top: 40px;
        display: flex;
        justify-content: flex-end;
        .alert_buttons {
        }
        .alert_button {
          position: absolute;
          left: 50%;
          transform: translate(-50%, -100%);
        }
      }
    }
  }
</style>
